$(document).ready(function(){
   var $content = $('#nhanxet');

    $('#comment-form').submit(function(event) {
       event.preventDefault();
        var empyRegex = /^\s*$/;

        if (empyRegex.test($('#hoten').val())) {
            $('#hoten').val('anonymous');
        }

        if (empyRegex.test($content.val())) {
            jModal.open({
                content: 'You must enter comment!',
                title: 'Error',
                type: 'error',
                on_close: function() {
                    $content.focus();
                }
            });
        } else {
            $.post(Py.markUpUrl('dienthoai/comment'), {
                dt_id: $('#dt_id').val(),
                nhanxet: $content.val(),
                hoten: $('#hoten').val(),
                email: $('#email').val()
            }, function(data) {
                if (data['code'] == 0) {

                    var $newComment = $('<div class="comment"></div>').append(
                        $('<h3></h3>').append(
                            $('<strong></strong>').text($('#hoten').val()),
                            $('<em></em>').text($('#email').val()),
                            $('<span></span>').text(data['time'])
                        ),

                        $('<div class="comment-content"></div>').text($content.val())
                    ).hide();

                    $('#comments-wrap.hidden').removeClass('hidden').slideDown(300);

                    $('#comments').prepend($newComment);
                    $newComment.slideDown(500);
                    $content.val('');


                }
            }, 'json');
        }
   }) ;

});